/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alarmlistener;

import java.awt.AWTException;
import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import settings.MainSettingsManager;

/**
 *
 * @author rbs
 */
public class Main {
    /**
     * @param args the command line arguments
     * @throws IOException
     * @throws InterruptedException 
     */

    public static void main(String[] args) throws IOException, InterruptedException, AWTException {

        MainSettingsManager.load();
        
        File folder = new File(getProgramPath() + "log");
        folder.mkdirs();
        
        FileHandler file = new FileHandler(getProgramPath() + "log" + File.separator + "alarmlistener.log", true);
        file.setFormatter(new SimpleFormatter());
        Logger.getLogger("").addHandler(file);
        Logger.getLogger("").setLevel(Level.ALL);

        Logger logger = Logger.getLogger(Main.class.toString());
        logger.setLevel(Level.ALL);
        
        logger.log(Level.INFO, "Alarmlistener wurde gestartet");
        TrayButton but = new TrayButton();
        SchleifenManager rics = new SchleifenManager();
        logger.log(Level.FINE, "Lese Daten von ini-Datei...");


        logger.log(Level.FINE, "Starte Server-Thread");
        ListeningServerThread serv = new ListeningServerThread(rics.getExpressRIC(), rics);
        serv.start();
        serv.join();
    }
    
        public static String getProgramPath() {
        
        File file = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getFile());
        System.out.println("Path: "  +  file.getParent());
        return file.getParent() + File.separator;
    }
        
}
